﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.ServiceModel;
using Fishing.WCFContracts;
using System.ServiceModel.Description;

namespace Fishing.WinService
{
    public partial class FishingWinService : ServiceBase
    {
        ServiceHost m_Host;

        public FishingWinService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            if (m_Host != null)
            {
                m_Host.Close();
            }
            //Create a URI to serve as the base address
            Uri httpUrl = new Uri("http://localhost:8090/MyService/FishingContracts");
            //Create ServiceHost
            m_Host = new ServiceHost
            (typeof(FangbuchProvider), httpUrl);
            //Add a service endpoint

            WSHttpBinding binding = new WSHttpBinding(SecurityMode.None);
            m_Host.AddServiceEndpoint
            (typeof(IFangbuchProvider), binding, "");
            //Enable metadata exchange
            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
            smb.HttpGetEnabled = true;
            m_Host.Description.Behaviors.Add(smb);
            //Start the Service
            m_Host.Open();


        }

        protected override void OnStop()
        {
            if (m_Host != null)
            {
                m_Host.Close();
                m_Host = null;
            }
        }
        //static void Main()
        //{
        //    ServiceBase[] ServicesToRun;
        //    ServicesToRun = new ServiceBase[] 
        //    { 
        //        new FishingWinService() 
        //    };
        //    ServiceBase.Run(ServicesToRun);

        //}
    }
}
